/*******************************************************************************
 * Copyright (c) 2010 Marcelo Cataldo, Sangeeth Nambiar
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * GraphViewPart.java
 * 
 * View part to display the dependency graph
 * 
 * Contributors:
 *    Marcelo Cataldo  - initial implementation 
 *    Sangeeth Nambiar - initial implementation
 *******************************************************************************/
package edu.cmu.isr.dinvenio.ui.views;

import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;

public class GraphViewPart extends ViewPart implements ISelectionListener{

	private Composite parent;
	private Frame awtFrame;
	public Panel awtPanel;


	public GraphViewPart() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void createPartControl(Composite parent) {
		this.parent = parent;		    
		Composite awtContainer = new Composite(parent, SWT.EMBEDDED);
		awtFrame = SWT_AWT.new_Frame(awtContainer);
		awtPanel = new java.awt.Panel();		
		awtPanel.addComponentListener(new ComponentListener() {
				@Override
				public void componentResized(ComponentEvent arg0) {
					edu.cmu.isr.dinvenio.Activator.myController.refreshGraphSize();
				}
				@Override
				public void componentHidden(ComponentEvent arg0) {}	
				@Override
				public void componentMoved(ComponentEvent arg0) {}
				@Override
				public void componentShown(ComponentEvent arg0) {}			
			}
		);
		awtFrame.add(awtPanel, java.awt.BorderLayout.CENTER);

		makeActions();
		hookContextMenu();
		hookDoubleClickAction();
		contributeToActionBars();


	}

	private void contributeToActionBars() {
		IActionBars bars = getViewSite().getActionBars();
		fillLocalPullDown(bars.getMenuManager());
		fillLocalToolBar(bars.getToolBarManager());				
	}

	private void fillLocalPullDown(IMenuManager menuManager) {
		// TODO Auto-generated method stub		
	}

	private void hookDoubleClickAction() {
		// TODO Auto-generated method stub
		
	}

	private void hookContextMenu() {
		// TODO Auto-generated method stub
	
	}

	private void makeActions() {			
	}
	
	private void fillLocalToolBar(IToolBarManager manager) {
	}
	

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
//		if (part instanceof ProjectView && selection instanceof IStructuredSelection) {
//			Object objectSelected = ((IStructuredSelection)selection).getFirstElement();
//			if(objectSelected instanceof RootImpl){
//				JungViewPart.this.setSwProject((RootImpl)objectSelected);
//			}
//		}		
	}
	@SuppressWarnings("deprecation")
	public void refresh(){
		parent.layout(true);
		//panel.vv.repaint();
		awtFrame.show();
	}

	public void disposeWidgets() {
		awtPanel.removeAll();		
	}

}
